package day20240908;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/MyMethod")
public class MyMethod extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        boolean flag = true;
        PrintWriter writer = resp.getWriter();
        String len = req.getParameter("len");
        String page = req.getParameter("page");
        if ("1".equals(len) && "1".equals(page)) {
            String method = req.getMethod();
            String contextPath = req.getContextPath();
            StringBuffer requestURL = req.getRequestURL();
            String requestURI = req.getRequestURI();
            String queryString = req.getQueryString();
            writer.write("""
                    <html>
                    <body>
                    method  ===  
                    """
                    +
                    method
                    +
                    """ 
                            <hr>
                            contextPath  ===  
                             """
                    +
                    contextPath
                    +
                    """
                            <hr>
                             requestURL  ===  
                             """
                    +
                    requestURL
                    +
                    """
                                                  
                            <hr> 
                            requestURI  ===  
                             """
                    +
                    requestURI
                    +
                    """
                            <hr> 
                            queryString  ===  
                            """
                    +
                    queryString
                    +
                    """
                            </body>
                            </html>
                            """);
            flag = false;
        }
        if (flag)
            writer.write("null!!!");
    }
}
